{	Problem: http://codeforces.ru/problemset/problem/24/A
 	Verdict: Accepted
}
uses math;
var i,n,s,q,x,t:longint; l,r,c:array[1..110] of longint;
begin
read(n);
s:=0;
for i:=1 to n do begin
  read(l[i],r[i],c[i]);
  inc(s,c[i]);
end;
x:=r[1];
q:=0;
t:=1;
while x<>l[1] do
  for i:=1 to n do
    if i<>t then begin
      if l[i]=x then begin
        t:=i;
        x:=r[i];
        break;
      end;
      if r[i]=x then begin
        inc(q,c[i]);
        t:=i;
        x:=l[i];
        break;
      end;
    end;
writeln(min(q,s-q));
end.